﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace TestDrive
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            this.Loaded += new RoutedEventHandler(MainWindow_Loaded);
        }
        intelliSys.Management.Automation.Test.AdvancedTextBox[] textBoxes = new intelliSys.Management.Automation.Test.AdvancedTextBox[7];
        string[] openXmls = new string[7];
        int i = 0;
        void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            for (int i = 0; i <= 6; i++)
            {
                textBoxes[i] = this.FindName("_" + (i + 1)) as intelliSys.Management.Automation.Test.AdvancedTextBox;
            }
        }

        private void Merge_Click(object sender, RoutedEventArgs e)
        {
            intelliSys.Management.Automation.Test.WordGenerationTask tsk = new intelliSys.Management.Automation.Test.WordGenerationTask();
            tsk.ReportProgress += new EventHandler<intelliSys.Management.Automation.Test.WordGenerationEventArgs>(tsk_ReportProgress);
        //tsk.MergeFile(new string[]{textBoxes[0].OriginalText,textBoxes[1].OriginalText,textBoxes[2].OriginalText,
        //    textBoxes[3].OriginalText,textBoxes[4].OriginalText,textBoxes[5].OriginalText,textBoxes[6].OriginalText});
        }

        void tsk_ReportProgress(object sender, intelliSys.Management.Automation.Test.WordGenerationEventArgs e)
        {
            this.Dispatcher.Invoke(new Action(() =>
                {
                    this.Title = double.Parse(e.Percentage) * 100 + "%";
                }));
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            var interopData = "";
            var BdyText = textBoxes[i % 7];
            i++;
            try
            {
                interopData = Clipboard.GetData("intelliSys.Management.Automation.Test").ToString();
            }
            catch (NullReferenceException)
            {
                return;
            }
            string orig;
            string displayed;
            BdyText.OpenXMLEnabled = true;
            intelliSys.Management.Automation.Test.Interop.OpenXMLInteropHelper.GetOpenParts(interopData, out orig, out displayed);
            BdyText.DisplayedTextWhileOpenXMLEnabled = displayed;
            BdyText.OriginalText = orig;
            BdyText.IsReadOnly = true;
        }
    }
}
